home *** CD-ROM | disk | FTP | other *** search
/ MacWorld Secrets (4th Edition) / Mac Secrets CD 4th Ed.toast / Apple Advanced Technologies / Apple Speech Technologies 1.5 / PlainTalk Developer Info / Speech Recognition Manager SDK / SR Sample Code / IM SR Example / MyProcessRecognitionResult.c < prev    next >
C/C++ Source or Header  |  1996-05-02  |  2KB  |  87 lines

  1. #include <SpeechRecognition.h>
  2. #include <stdio.h>
  3.  
  4. void MyProcessRecognitionResult (SRRecognitionResult recResult);
  5.  
  6. extern OSErr MyCallPersonInPath (SRPath recognizedPath);
  7.  
  8. #define            kTopLMRefCon         'top '
  9. #define            kCallPersonRefCon    'call'
  10. #define            kRejectedWordRefCon    'rejc'
  11.  
  12. void MyProcessRecognitionResult (SRRecognitionResult recResult)
  13. {
  14.     OSErr                myErr = noErr;
  15.  
  16.     if (recResult) {
  17.         SRLanguageModel    myResultLM;
  18.         Size            myLen;
  19.         
  20.         myLen = sizeof (myResultLM);
  21.         myErr = SRGetProperty (recResult, kSRLanguageModelFormat, &myResultLM, &myLen);
  22.         
  23.         if (!myErr)    {
  24.             long                 myRefCon;
  25.             SRLanguageObject    mySubElement;
  26.             
  27.             myLen = sizeof (myRefCon);
  28.             myErr = SRGetProperty (myResultLM, kSRRefCon, &myRefCon, &myLen);
  29.             
  30.             if (!myErr) {
  31.                 switch (myRefCon) {
  32.                     case kRejectedWordRefCon:
  33.                         /* Here we do nothing if the utterace was rejected */
  34.                         break;
  35.                     
  36.                     case kTopLMRefCon:
  37.                         /*    if it's a valid result from our top-level LM,     */
  38.                         /*    then parse and process its elements             */
  39.                         
  40.                         /* TopLM one sub-element, one of the following:        */
  41.                         /* "<call><person>" (SRPath with kCallPersonRefCon),*/
  42.                         /* "schedule meeting with <person>" (SRPath), or    */
  43.                         /* "view today's schedule" (SRPhrase)                 */
  44.                         
  45.                         /* we get the sub-element                            */
  46.                         myErr = SRGetIndexedItem (myResultLM, &mySubElement, 0);
  47.                         if (!myErr) {
  48.                             myLen = sizeof (myRefCon);
  49.                             myErr = SRGetProperty (mySubElement, kSRRefCon, &myRefCon, &myLen);
  50.                             
  51.                             /* Call a subroutine to process the subelement    */
  52.                             if (!myErr) switch (myRefCon)
  53.                                 {
  54.                                 case kCallPersonRefCon:
  55.                                     myErr = MyCallPersonInPath 
  56.                                                         ((SRPath) mySubElement);
  57.                                     break;
  58.                                 
  59.                                 /* ...process "schedule meeting with <person>"*/
  60.                                 
  61.                                 /* ...process "view today's schedule"         */
  62.                                 
  63.                                 default:
  64.                                     break;
  65.                                 }
  66.                             
  67.                             /* release subelement when done with it         */
  68.                             myErr = SRReleaseObject (mySubElement);
  69.                         }
  70.                         break;
  71.                     
  72.                     default:
  73.                         break;
  74.                 }
  75.             }
  76.             
  77.             /*    release myResultLM fetched above when done with it             */
  78.             myErr = SRReleaseObject (myResultLM);
  79.         }
  80.         
  81.         /* Release SRRecognitionResult since we are done with it             */
  82.         myErr = SRReleaseObject (recResult);
  83.     }
  84.     
  85. }
  86.  
  87.